// JavaScript Document
$(function(){

	//导航当前项
	$.fn.currentMenu=function(settings){
			st=$.extend({
				text: "home",
				style: "curr"
			},settings);
			st.text=st.text.toLowerCase();
			$(this).each(function(n){

				tmpText=$(this).children().eq(0).text().toLowerCase();
				tmpText=tmpText.replace(/ /,"");
				if(tmpText==st.text){

					$(this).addClass(st.style);
				}
			});
	}
	
	//下拉菜单  （三种效果show、fade、slide，speed设置速度）
		$.fn.showMenu=function(settings){
			settings=$.extend({
				effect: "show",		
				speed: 300
			},settings);
			if(settings.effect=="show"){
				this.hover(function(){ $(this).find("ul").show();     	},
								function(){ $(this).find("ul").hide();				});
			}else if(settings.effect=="fade"){
				this.hover(function(){ $(this).find("ul").fadeIn(settings.speed);     	},
								function(){ $(this).find("ul").fadeOut(settings.speed);				});	
			}else if(settings.effect=="slide"){
				this.hover(function(){ $(this).find("ul").slideDown(settings.speed);     	},
								function(){ $(this).find("ul").slideUp(settings.speed);				});		
			}
			return this;
		}
	
	//Tab切换
		$.fn.tabSwitch=function(settings){
			settings=$.extend({
				tabContent: "tab_cont",
				currentClass: "curr",
				firstShow: 1
			},settings);
			$(this).children().eq(settings.firstShow-1).addClass(settings.currentClass);
			$("."+settings.tabContent).hide().eq(settings.firstShow-1).show();
			$(this).children().each(function(n){ $(this).attr("index",n);	});			
			$(this).children().click(function(){
					var currIndex=parseInt($(this).attr("index"));
					$(this).addClass(settings.currentClass).siblings().removeClass(settings.currentClass);
					$("."+settings.tabContent).eq(currIndex).show().siblings("."+settings.tabContent).hide();
			});
			return this;
		}
		
	//弹出内容
		$.fn.showContent=function(settings){
			st=$.extend({
				closeStyle:"#close"			
			},settings);	
			st.oTarget=null;
			$($(this).attr("href")).css({display:"none"});
			$(this).click(function(){
				showBg();
				st.oTarget=$(this).attr("href");
				sTop=document.documentElement.clientHeight-$(st.oTarget).height();				
				sTop=sTop/2+document.documentElement.scrollTop;				
				sLeft=($("body").width()-$(st.oTarget).width())/2;				
				$(st.oTarget).css({
					position:"absolute",
					left:sLeft+"px",
					top:sTop+"px",
					zIndex:200
				}).fadeIn();
				return false;
			});
			function showBg(){
				$("body").append("<div id='showBg'></div>");
				$("#showBg").css({
					display:"none",
					position:"absolute",
					top:"0px",
					left:"0px",
					zIndex:1,
					width:$(document).width()+"px",
					height:$(document).height()+"px",
					background:"#000",
					opacity:0.7
				}).fadeIn();
				$("#showBg").click(function(){
					$(this).fadeOut();
					$(st.oTarget).fadeOut();
				});				
			}
			$(st.closeStyle).css({cursor:"pointer"}).click(function(){
					$("#showBg").fadeOut();
					$(st.oTarget).fadeOut();
				});			
		}

});